package com.traykai.web.meeting.demo.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.traykai.web.meeting.demo.mapper.DemoMapper;
import com.traykai.web.meeting.demo.vo.ArticleVo;
import com.traykai.web.meeting.demo.vo.Comment2Vo;
import com.traykai.web.meeting.demo.vo.CommentVo;
import com.traykai.web.meeting.demo.vo.TypeVo;

/**
 * 业务处理Service层
 * DemoService
 *
 * @author lengqx
 * @date 2016年6月15日下午2:22:37
 */
@Service
public class DemoService {
	
	@Autowired
	private DemoMapper demoMapper;
	
	/**
	 * 查询文章类型
	 * queryTypeById
	 *
	 * @param id
	 * @return
	 */
	public TypeVo queryTypeById(int id){
		return demoMapper.selectTypeById(id);
	}
	
	/**
	 *查询文章类型列表 
	 * queryTypes
	 *
	 * @return
	 */
	public List<TypeVo> queryTypes(){
		return demoMapper.selectTypeList();
	}
	
	/**
	 * 保存文章
	 * saveArticle
	 *
	 * @param vo
	 * @throws Exception
	 */
	public void saveArticle(ArticleVo vo) throws Exception{
		demoMapper.saveArticle(vo);
	}
	
	/**
	 * 查询文章内容
	 * selectArticleById
	 *
	 * @param id
	 * @return
	 */
	public ArticleVo selectArticleById(int id){
		return demoMapper.selectArticleById(id);
	}

	/**
	 * 查询文章列表
	 * queryArticlesByTypeId
	 *
	 * @param id
	 * @return
	 */
	public List<ArticleVo> queryArticlesByTypeId(int id){
		return demoMapper.selectArticleListByTypeId(id);
	}
	
	/**
	 * 查询所有文章
	 * queryArticles
	 *
	 * @return
	 */
	public List<ArticleVo> queryArticles(){
		return demoMapper.selectArticleList();
	}
	
	/**
	 * 保存评论内容
	 * saveComment
	 *
	 * @param vo
	 * @throws Exception
	 */
	public void saveComment(CommentVo vo) throws Exception{
		demoMapper.insertComment(vo);
	}
	
	/**
	 * 查询文章的评论列表
	 * selectCommentsByArticleId
	 *
	 * @param articleId
	 * @return
	 */
	public List<CommentVo> selectCommentsByArticleId(int articleId){
		return demoMapper.selectCommentsByArticleId(articleId);
	}
	
	/**
	 * 更新评论次数
	 * updateCommentNum
	 *
	 * @param articleId
	 * @throws Exception
	 */
	public void updateCommentNum(int articleId) throws Exception{
		demoMapper.updateCommentNum(articleId);
	}
	
	/**
	 * 查询评论内容
	 * selectCommentVoById
	 *
	 * @param id
	 * @return
	 */
	public CommentVo selectCommentVoById(int id){
		return demoMapper.selectCommentById(id);
	}
	
//	第二种评论处理方式
	public void saveCommentCopy(Comment2Vo vo) throws Exception{
		demoMapper.insertCommentCopy(vo);
	}
	
	public Comment2Vo selectCommentCopyById(int id){
		return demoMapper.selectCommentCopyById(id);
	}
	
	public List<Comment2Vo> selectCommentCopyChildrenByParentId(int parentId){
		return demoMapper.selectCommentCopyChildrenByParentId(parentId);
	}
	
	public List<Comment2Vo> selectCommentCopysByArticleId(int articleId){
		return demoMapper.selectCommentCopysByArticleId(articleId);
	}
}
